<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Le classement HitQuizz !</title>
	<link rel ="stylesheet" type="text/css" href="css/reset.css">
	<link rel ="stylesheet" type="text/css" href="css/style.css">
	
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
	
	<?php
		require 'src/facebook.php';
		
		$facebook = new Facebook(array(
		  'appId'  => '111934045501569',
		  'secret' => 'd9cd918a707fe75518a233b602ad2244',
		 // 'fileUpload' => true, 
		  'cookie' => true
		));
		//$facebook->setFileUploadSupport(true);
		
		$user = $facebook->getUser();
		
		if ($user) {
		  try {
		    // Proceed knowing you have a logged in user who's authenticated.
		    $user_profile = $facebook->api('/me');
		  } catch (FacebookApiException $e) {
		    error_log($e);
		    $user = null;
		  }
		}
		
		// Login or logout url will be needed depending on current user state.
		if ($user) {
		  $logoutUrl = $facebook->getLogoutUrl();
		} else {
		  $loginUrl = $facebook->getLoginUrl();
		}
		
		$user_profile = $facebook->api('/me');
		
		$bdd = new PDO('mysql:host=localhost;dbname=hitquizz', 'root', 'root');
	?>
	
</head>

<body>
<div id="fb-root"></div>
	<div id="container">
		<div class="header">
			<div class="col-left">
		    	<div class="col-left">
				<div id="user-infos">
		    		<div class="user-pic"><!-- User picture call --></div>
		    		<div class="user-name"><!-- User name call --></div>
		    	</div>
		        <?php 
					$reponse = $bdd->query('SELECT score, trophee, friends, credit FROM users WHERE id_facebook='.$user_profile['id'].'');
    
					while ($donnees = $reponse->fetch())
					{
					?>
						<div class="user-tab-infos">
			        	<p>Score: <span><?php echo $donnees['score'];  ?></span></p>
			            <p>Trophés: <span><?php echo $donnees['trophee'] ?></span></p>
			            <p>Amis: <span><?php echo $donnees['friends'] ?></span></p>
			            <p>Crédits: <span><?php echo $donnees['credit'] ?></span></p>
						</div>
					<?php	
					}
				?>
		    </div>
		    </div>
	        <div class="logo">
	        	<div><a href="index.php"><img src="images/logo.png" alt="HQ !"/></a></div>
	        </div>
	        <div class="col-right">
		        <div class="fb-like" data-href="http://localhost/" data-send="false" data-layout="button_count" data-width="100" data-show-faces="false"></div>
		        <div class="fb-send" data-href="http://localhost/"></div>
		        <div class="back-button"><a href="#">Revenir sur ma page</a></div>
		    </div>
	    </div>
	    <div class="content">
	    	<ul class="classification-wrapper">
	    		<li class="">
	    			<span><!-- User image called here --></span>
	    			<h2><!--  User name called here --></h2>
	    			<h3>10000 pts</h3>
	    		</li>
	    		<li class="">
	    			<span><!-- Image user called here --></span>
	    			<h2><!--  User name called here --></h2>
	    			<h3>10000 pts</h3>
	    		</li>
	    		<li class="">
	    			<span><!-- Image user called here --></span>
	    			<h2><!--  User name called here --></h2>
	    			<h3>10000 pts</h3>
	    		</li><?php
			$reponse = $bdd->query('SELECT username, score, id_facebook FROM users ORDER BY score');
			while ($donnees = $reponse->fetch())
				{
				?>
					<li>
	    			<span><?php echo '<img src="https://graph.facebook.com/' . $donnees['id_facebook'] . '/picture" />'; ?></span> 
	    			<h2><?php echo $donnees['username'] ?></h2>
	    			<h3><?php echo $donnees['score'];  ?> pts</h3>
					</li>
				<?php
				}
				?>
	    	</ul>
	    	<div class="footer">© Copyright 2011 HitQuizz - <a href="mentions.php">Mentions Légales</a></div>
		</div>
		</div>
	<script type="text/javascript" src="js/facebook.js"></script>
</body>
</html>
